<template>
    <el-dialog
            :title="!dataForm.id ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="解读ID，主键" prop="id">
                        <el-input v-model.number="dataForm.id" placeholder="解读ID，主键"></el-input>
                </el-form-item>
                <el-form-item label="关联政策ID，对应app_policy表中的id" prop="policyId">
                        <el-input v-model.number="dataForm.policyId" placeholder="关联政策ID，对应app_policy表中的id"></el-input>
                </el-form-item>
                <el-form-item label="解读发布日期" prop="interpretationDate">
                        <el-date-picker
                                v-model="dataForm.interpretationDate"
                                type="datetime"
                                placeholder="解读发布日期">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="宣传渠道，如官网、公众号、线下活动等" prop="channel">
                        <el-input v-model="dataForm.channel" placeholder="宣传渠道，如官网、公众号、线下活动等"></el-input>
                </el-form-item>
                <el-form-item label="解读状态" prop="status">
                        <el-input v-model="dataForm.status" placeholder="解读状态"></el-input>
                </el-form-item>
                <el-form-item label="记录创建时间" prop="createTime">
                        <el-date-picker
                                v-model="dataForm.createTime"
                                type="datetime"
                                placeholder="记录创建时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="记录更新时间" prop="updateTime">
                        <el-date-picker
                                v-model="dataForm.updateTime"
                                type="datetime"
                                placeholder="记录更新时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="政策解读内容" prop="interpretationContent">
                        <el-input v-model="dataForm.interpretationContent" placeholder="政策解读内容"></el-input>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
      data () {
        return {
          visible: false,
          dataForm: {
            id: null,
            policyId: null,
            interpretationDate: null,
            channel: null,
            status: null,
            createTime: null,
            updateTime: null,
            interpretationContent: null
          },
          dataRule: {
            id: [
                        { required: true, message: '解读ID，主键不能为空', trigger: 'blur' }
            ],
            policyId: [
                        { required: true, message: '关联政策ID，对应app_policy表中的id不能为空', trigger: 'blur' }
            ],
            interpretationDate: [
                        { required: true, message: '解读发布日期不能为空', trigger: 'blur' }
            ],
            channel: [
                        { required: true, message: '宣传渠道，如官网、公众号、线下活动等不能为空', trigger: 'blur' }
            ],
            status: [
                        { required: true, message: '解读状态不能为空', trigger: 'blur' }
            ],
            createTime: [
                        { required: true, message: '记录创建时间不能为空', trigger: 'blur' }
            ],
            updateTime: [
                        { required: true, message: '记录更新时间不能为空', trigger: 'blur' }
            ],
            interpretationContent: [
                        { required: true, message: '政策解读内容不能为空', trigger: 'blur' }
            ]
          }
        }
      },
      methods: {
        init (id) {
          this.dataForm.id = id || 0
          this.visible = true
          this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
            this.dataForm.id = id || 0
            if (this.dataForm.id) {
              this.$http({
                url: this.$http.adornUrl(`/app/policy_interpretation/info/${this.dataForm.id}`),
                method: 'get',
                params: this.$http.adornParams()
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.dataForm = data.apppolicyinterpretation
                }
              })
            }
          })
        },
            // 表单提交
        dataFormSubmit () {
          this.$refs['dataForm'].validate((valid) => {
            if (valid) {
              this.$http({
                url: this.$http.adornUrl(`/app/policy_interpretation/${!this.dataForm.id ? 'save' : 'update'}`),
                method: 'post',
                data: this.$http.adornData(this.dataForm)
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                      this.visible = false
                      this.$emit('refreshDataList')
                    }
                  })
                } else {
                  this.$message.error(data.msg)
                }
              })
            }
          })
        }
      }
    }
</script>